package com.example.messagewall.Controller;

import com.example.messagewall.Mapper.MessageInfoMapper;
import com.example.messagewall.Model.MessageInfo;
import com.example.messagewall.Service.MessageInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/message")
@RestController
public class MessageController {
    @Autowired
    private MessageInfoService messageInfoService;



    @RequestMapping("/getList")
    public List<MessageInfo> getList(){
        return messageInfoService.selectAll();
    }
    @RequestMapping(value = "/addMessage",method = RequestMethod.POST)
    public boolean insertInto( @RequestBody MessageInfo messageInfo){
        messageInfoService.insert2(messageInfo);

        System.out.println(messageInfo);
        return true;

//        if(StringUtils.hasLength(messageInfo.getFrom())&&
//        StringUtils.hasLength(messageInfo.getTo())&&
//        StringUtils.hasLength(messageInfo.getMessage())){
//            messageInfoService.insertInto(messageInfo);
//            return true;
//        }
        //return false;

    }

}
